<?php
require_once(OC::$SERVERROOT . "/apps/reports/lib/helper.php");
require_once(OC::$SERVERROOT . "/apps/reports/lib/reports.php");

if (!PFactory::isMasterUser()) {
   echo '您无权访问该资源';
   exit();
}

$start = JRequest::getString('start', '');
$end = JRequest::getString('end', '');
$xtypes = array('resume', 'event', 'offer', 'entry');

$model = new PReportsModelReports();
$summary = $model->getOneJobSummary();

if ($summary === false) {
   jexit('<div class="yahei large noreportsdata">' . ($model->getError() ? $model->getError() : '系统错误') . '</div>');
}

$statusList = array('resume', 'fgood', 'fbad', 'pending', 'event', 'retest', 'absent', 'egood', 'ebad', 'offer', 'entry');
$tmpl = new OCP\Template('reports', 'part.reports.resumechart', '');
$tmpl->assign('summary', $summary);
?>

<div class="rep_resumefrom" style="margin-top:20px;" id="anchor_trend">
   <h5><b>趋势情况</b></h5>
   <div class="rep_datashow">
      <span><i class="c1"></i> 新增简历<b style="margin-right:10px;"><?=$summary['date']['total']['dupResume']?></b>(不重复<b><?=$summary['date']['total']['resume']?></b>)</span>
      <em></em>
      <span><i class="c2"></i> 进入面试<b><?=$summary['date']['total']['event']?></b></span>
      <em></em>
      <span><i class="c3"></i> 发offer<b><?=$summary['date']['total']['offer']?></b></span>
      <em></em>
      <span><i class="c4"></i> 入职<b><?=$summary['date']['total']['entry']?></b></span>
   </div>

   <div class="putcanvas">
      <div id="dateLine" style="height:215px; width:100%;"></div>
   </div>
</div>

<div class="rep_resumefrom" id="anchor_zhaopin">
   <h5><b>招聘情况</b></h5>

   <div class="clearfix">
      <div class="rep_detailtable pull-left" style="width:100%; margin-bottom:15px;">
         <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
               <th width="%">新增简历</th>
               <th width="%">筛选合格</th>
               <th width="%">筛选不合格</th>
               <th width="%">筛选结果待定</th>
               <th width="%">面试</th>
               <th width="%">复试</th>
               <th width="%">缺席</th>
               <th width="%">面试合格</th>
               <th width="%">面试不合格</th>
               <th width="%">发offer</th>
               <th width="%">入职</th>
            </tr>
            <tr>
               <? foreach ($statusList as $s): ?>
                  <td><?=(!empty($summary['status']['total'][$s]) ? $summary['status']['total'][$s] : 0)?></td>
               <? endforeach; ?>
            </tr>
         </table>
      </div>

      <div class="pull-left" style="width:50%">
         <? if (!empty($summary['prostatus']['pie']['data'])): ?>
            <div id="processPie" style="height:165px; width:410px; margin:4px auto;"></div>
         <? else: ?>
            <div class="nodatacolor" style="text-align: center; margin-top: 70px;">暂无数据</div>
         <? endif; ?>
      </div>

      <div class="rep_detailtable pull-right" style="width:50%; margin-top:10px;">
         <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
               <th width="44%">简历状态</th>
               <th width="28%">简历数</th>
               <th width="28%">比例</th>
            </tr>
            <tr>
               <td class="medium">已处理<br><span style="color:#999999;">(已加标签 \ 改状态 \ 写备注评语)</span></td>
               <td><?=$summary['prostatus']['total']['processed']['count']?></td>
               <td><?=$summary['prostatus']['total']['processed']['weight']?></td>
            </tr>
            <tr>
               <td class="medium">未处理</td>
               <td><?=$summary['prostatus']['total']['unprocessed']['count']?></td>
               <td><?=$summary['prostatus']['total']['unprocessed']['weight']?></td>
            </tr>
         </table>
      </div>
   </div>
</div>

<?php $tmpl->printpage(); ?>

<? if(0): ?>
<div class="rep_resumefrom" id="anchor_from">
   <h5><b>来源情况</b></h5>

   <div class="clearfix">
      <div class="pull-left" style="width:50%;">
         <? if (!empty($summary['source']['pie']['data'])): ?>
            <div id="sourcePie" style="height:165px; width:410px; margin:auto;"></div>
         <? else: ?>
            <div class="nodatacolor" style="width:410px; margin:auto; text-align: center; padding-top: 20px;">暂无数据</div>
         <? endif; ?>
      </div>

      <div class="rep_detailtable pull-right" style="width:50%;">
         <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
               <th width="30%">简历来源</th>
               <th width="35%">简历数</th>
               <th width="35%">比例</th>
            </tr>
            <? if (!empty($summary['source']['total'])):
               $sourceList = array(
                  'upload' => array('text' => '枇杷派', 'class' => 'pipapai'),
                  '51job' => array('text' => '前程无忧', 'class' => 'job51'),
                  'zhilian' => array('text' => '智联招聘', 'class' => 'zhilian'),
                  'jiancai' => array('text' => '建筑英才', 'class' => 'jiancai')
               );
               $sources = array_keys($summary['source']['total']);
               $sources_sorted = array_keys($sourceList);
               $sources = array_values(array_intersect($sources_sorted, $sources));
               foreach($sources as $s):
                  $t = $summary['source']['total'][$s];
               ?>
               <tr>
                  <td class="tleft"><i class="<?=$sourceList[$s]['class']?>"></i> <?=$sourceList[$s]['text']?></td>
                  <td><?=$t['count']?></td>
                  <td><?=$t['weight']?></td>
               </tr>
               <? endforeach; ?>
            <? else: ?>
               <tr><td colspan="3"><div class="nodatacolor">暂无数据</div></td></tr>
            <? endif; ?>
         </table>
      </div>
   </div>
</div>

<?php
$resumeParseList = array(
   'match_degree' => array(
      'text'    => '匹配度',
      'weights' => array('20%以下/其他', '20%-50%', '50%-75%', '75%-100%'),
      'show'    => 1
   ),
   'degree_level' => array(
      'text'    => '学历',
      'weights' => array('初中及以下', '高中/中专', '大专', '本科', '硕士及以上'),
      'show'    => 1
   ),
   'workexp' => array(
      'text'    => '工作经验',
      'weights' => array('应届毕业生', '不满1年', '1-2年', '2-5年', '5-10年', '10年以上'),
      'show'    => 1
   ),
   'target_salary' => array(
      'text'    => '期望月薪',
      'weights' => array('2000元以下', '2000-5000元', '5000-8000元', '8000-10000元', '10000元以上'),
      'show'    => 0
   ),
   'age' => array(
      'text'    => '年龄',
      'weights' => array('25岁以下', '25-30岁', '30-35岁', '35-40岁', '40-50岁', '50岁以上'),
      'show'    => 0
   ),
   'sex' => array(
      'text'    => '性别',
      'weights' => array('男', '女'),
      'show'    => 0
   )
);
?>
<div class="rep_resumefrom" id="anchor_resumeparse">
   <h5 id="resumeParseTitle">
      <b>人才分析</b>
      <? foreach ($resumeParseList as $w => $r): ?>
         <label class="checkbox inline <?=($r['show'] ? 'checkedbox' : '')?>">
            <input type="checkbox" data-target=".<?=$w?>" class="resumeparse" <?=($r['show'] ? 'checked="checked"' : '')?>> <?=$r['text']?>
         </label>
      <? endforeach; ?>
      <!--
      <label class="checkbox inline">
         <input type="checkbox" id="" value=""> 职能类别
      </label>
      <label class="checkbox inline">
         <input type="checkbox" id="" value=""> 行业
      </label>
      -->
   </h5>

   <? if (!empty($summary['resumeParse']['donuts'])): ?>
      <? foreach ($resumeParseList as $w => $r): ?>
         <div class="item <?=$w?> <?=($r['show'] ? '' : 'hide')?> clearfix">
            <div class="pull-left rep_checkedname"><?=$r['text']?></div>

            <div class="pull-left" style="width:50%;">
               <? if (!empty($summary['resumeParse']['donuts'][$w])): ?>
                  <div id="<?=$w?>Resume" class="resumeDonut <?=($r['show'] ? 'show' : '')?>" data-wtype="<?=$w?>" style="height:165px; width:410px; margin:auto;"></div>
               <? else: ?>
                  <div class="nodatacolor" style="text-align: center; padding-top: 15px;">暂无数据</div>
               <? endif; ?>
            </div>

            <div class="rep_detailtable pull-right" style="width:50%;">
               <table width="100%" border="0" cellpadding="0" cellspacing="0">
                  <tr>
                     <th width="40%"><?=$r['text']?></th>
                     <th width="30%">简历数</th>
                     <th width="30%">比例</th>
                  </tr>
                  <? if (!empty($summary['resumeParse']['total'][$w])): ?>
                     <? foreach ($summary['resumeParse']['total'][$w] as $wtext => $data): ?>
                        <tr>
                           <td class="tleft"><?=$wtext?></td>
                           <td><?=$data['count']?></td>
                           <td><?=$data['weight']?></td>
                        </tr>
                     <? endforeach; ?>
                  <? else: ?>
                     <tr><td><div class="nodatacolor">暂无数据</div></td></tr>
                  <? endif; ?>
               </table>
            </div>
         </div>
      <? endforeach; ?>
   <? else: ?>
      <div class="clearfix nodatacolor" style="text-align: center; padding-bottom: 15px;">暂无数据</div>
   <? endif; ?>
   <div class="noItem hide clearfix" style="text-align: center; padding-bottom: 15px;">请选择分析项目</div>
</div>
<? endif; ?>

<script type="text/javascript">
$(document).ready(function(){
   var summary = <?=json_encode($summary)?>;
   var charts = new Array();
   $(window).unbind('resize');

   if($("#dateLine").length > 0) {
      charts[charts.length++] = $.jqplot('dateLine',  summary.date.lines.data, {
         seriesColors: [ '#999999', '#06aaff', '#5fcb17', '#d9a300' ],
         axes:{
            xaxis:{
               renderer: $.jqplot.CategoryAxisRenderer,
               ticks: summary.date.lines.ticks
            },
            yaxis:{
               min: 0,
               max: summary.date.lines.max,
               tickInterval : summary.date.lines.tickInterval,
               tickOptions: {formatString: '%d'}
            }
         },
         seriesDefaults: {
            shadow:false,
            lineWidth:1.5,
            markerOptions:{
               shadow:false,
            },
         },
         series:[],
         highlighter: {
            show: true,
            sizeAdjust: 7.5,
            tooltipAxes: 'y',
            tooltipSeparator: ' - ',
            useAxesFormatters: true
         },
         cursor: {
            show: false
         },
         grid: {
            drawGridLines: false,        // wether to draw lines across the grid or not.
            gridLineColor: '#e9e9e9',   // *Color of the grid lines.
            background: '#ffffff',      // CSS color spec for background color of grid.
            borderColor: '#333333',     // CSS color spec for border around grid.
            borderWidth: 0.5,           // pixel width of border around grid.
            shadow: false,               // draw a shadow for grid.
            shadowAngle: 45,            // angle of the shadow.  Clockwise from x axis.
            shadowOffset: 1.5,          // offset from the line of the shadow.
            shadowWidth: 2,             // width of the stroke for the shadow.
            shadowDepth: 2,             // Number of strokes to make when drawing shadow.
            shadowAlpha: 0.07,         // Opacity of the shadow
         }
      });
   }

   if($("#processPie").length > 0) {
      $.jqplot ('processPie', [summary.prostatus.pie.data], {
         seriesColors: [ "#75ceff", "#e46562"],
         seriesDefaults: {
            // Make this a pie chart.
            renderer: jQuery.jqplot.PieRenderer,
            rendererOptions: {
               startAngle: -180,
               // Put data labels on the pie slices.
               // By default, labels show the percentage of the slice.
               dataLabels: summary.prostatus.pie.labels,
               showDataLabels: true,
               diameter: 118, // diameter of pie, auto computed by default.
               sliceMargin: 2,     // gap between slices.
               fill: true,         // render solid (filled) slices.
               shadow: false,
               shadowOffset: 2,    // offset of the shadow from the chart.
               shadowDepth: 5,     // Number of strokes to make when drawing shadow.  Each stroke
                                   // offset by shadowOffset from the last.
               shadowAlpha: 0.07,   // Opacity of the shadow
               dataLabelPositionFactor:1.4
            }
         },
         // Custom labels for the series are specified with the "label"
         // option on the series option.  Here a series option object
         // is specified for each series.
         series:[
            {showLabel:true,color:'#ffffff'}
         ],
         legend: {
            show:true,
            location: 'ne',
            border: '0',
            background: '#'
         },
         grid: {
            drawGridLines: false,        // wether to draw lines across the grid or not.
            gridLineColor: '#d3d3d3',   // *Color of the grid lines.
            background: '#ffffff',      // CSS color spec for background color of grid.
            borderColor: '#d3d3d3',     // CSS color spec for border around grid.
            borderWidth: 0,           // pixel width of border around grid.
            shadow: false,               // draw a shadow for grid.
         },
      });
   }

   $('.sourcePie').each(function(){
      var xtype = $(this).data('xtype');
      $.jqplot ($(this).attr('id'), [summary.source.pies[xtype]['data']], {
         seriesColors: summary.source.pies[xtype]['colors'],
         seriesDefaults: {
            // Make this a pie chart.
            renderer: jQuery.jqplot.PieRenderer,
            rendererOptions: {
               // Put data labels on the pie slices.
               // By default, labels show the percentage of the slice.
               dataLabels: summary.source.pies[xtype]['labels'],
               showDataLabels: true,
               diameter: 118,         // padding between pie and neighboring legend or plot margin.
               sliceMargin: 2,     // gap between slices.
               fill: true,         // render solid (filled) slices.
               startAngle: -180,
               shadow: false,
               shadowOffset: 2,    // offset of the shadow from the chart.
               shadowDepth: 5,     // Number of strokes to make when drawing shadow.  Each stroke
                                   // offset by shadowOffset from the last.
               shadowAlpha: 0.07,   // Opacity of the shadow
               dataLabelPositionFactor:1.3,
               dataLabelThreshold:0
               //dataLabelFormatString:'%.1f%',
            }
         },
         // Custom labels for the series are specified with the "label"
         // option on the series option.  Here a series option object
         // is specified for each series.
         legend: {
            show:false,
            location: 'e'
         },
         grid: {
            drawGridLines: false,        // wether to draw lines across the grid or not.
            gridLineColor: '#d3d3d3',   // *Color of the grid lines.
            background: '#ffffff',      // CSS color spec for background color of grid.
            borderColor: '#d3d3d3',     // CSS color spec for border around grid.
            borderWidth: 0,           // pixel width of border around grid.
            shadow: false,               // draw a shadow for grid.
         }
      });
   });

   var drawResumeDonut = function(target){
      var wtype = $(target).data('wtype');
      var xtype = $(target).data('xtype');

      $.jqplot($(target).attr('id'), [summary.resumeParse.donuts[wtype][xtype]['data']], {
         seriesColors: summary.resumeParse.donuts[wtype][xtype]['colors'],
         seriesDefaults: {
            // make this a donut chart.
            renderer:$.jqplot.DonutRenderer,
            rendererOptions:{
               shadow: false,
               diameter: 118,
               thickness: 13, 
               // Donut's can be cut into slices like pies.
               sliceMargin: 2,
               // Pies and donuts can start at any arbitrary angle.
               startAngle: -180,
               showDataLabels: true,
               // By default, data labels show the percentage of the donut/pie.
               // You can show the data 'value' or data 'label' instead.
               dataLabels: summary.resumeParse.donuts[wtype][xtype]['labels'],
               dataLabelPositionFactor:2.3,
               dataLabelThreshold:0
               //dataLabelFormatString:'%s%',
            }
         },
         grid: {
            drawGridLines: false,        // wether to draw lines across the grid or not.
            gridLineColor: '#d3d3d3',   // *Color of the grid lines.
            background: '#ffffff',      // CSS color spec for background color of grid.
            borderColor: '#d3d3d3',     // CSS color spec for border around grid.
            borderWidth: 0,           // pixel width of border around grid.
            shadow: false,               // draw a shadow for grid.
         },
         legend: {
            show:false,
            location: 'ne',
            border: '0',
            background: '#'
         }
      });
   }

   $('.rep_detailtable .resumeDonut.show').each(function(){
      drawResumeDonut($(this));
   });

   $('.rep_resumefrom').on('click', '.resumeparse', function(){
      var anchor = $($(this).data('anchor'));
      var target = $($(this).data('target'));
      if ($(this).prop('checked')) {
         $(this).closest(".checkbox").addClass("checkedbox");
         target.insertAfter('#resumeParseTitle').show().siblings('.noItem').hide().closest('.rep_detailtable').show();
         $('.resumeDonut', target).each(function(){
            drawResumeDonut($(this));
         });
         //if ($('.rep_resumefrom .resumeparse:checked').length <=1)
         if(anchor.length > 0)
            $('html,body').animate({scrollTop:anchor.offset().top-175},1000);
      } else {
         $(this).closest(".checkbox").removeClass("checkedbox");
         target.hide();
         if ($('.rep_resumefrom .resumeparse:checked').length <=0)
            target.siblings('.item').hide().siblings('.noItem').show();
      }
   });
   
   $(window).resize(function(){
      $.each(charts, function(i, c){
         c.replot( { resetAxes: { xaxis: true } } );
      });
   });
});
</script>
